package cn.lrl.auth.controller;


import cn.lrl.api.generation.pojo.User;
import cn.lrl.api.generation.service.UserService;
import com.alibaba.fastjson.JSON;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 * 前端控制器
 * </p>
 *
 * @author lrl
 * @since 2022-03-08
 */
@RestController
@RequestMapping("/user")
@Slf4j
public class UserController {
    @Autowired
    UserService userService;

    @PostMapping("/add")
    public boolean addUser(@RequestBody User user) {
        return false;
    }

    @GetMapping("/get/{id}")
    public User getUser(@PathVariable("id") Long id) {
        log.info("服务端接口暴露成功，获取消费端id：" + id);
        User user = userService.getOne(new QueryWrapper<User>().eq("id", id));
        if (user == null) {
            throw new RuntimeException("这个id=>" + id + ",不存在该用户，或信息无法找到~");
        }
        return user;
    }

    @GetMapping("/list")
    public List<User> getAll() {
        return userService.getBaseMapper().selectList(new QueryWrapper<User>());
    }
}

